package esgi.stationratp.adapters;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import esgi.stationratp.model.Station;

public class StationListViewAdapter extends ArrayAdapter<Station> {

	private final List<Station> _data;
	private Context _context;

	public StationListViewAdapter(Context context, int textViewResourceId,
			List<Station> objects) {
		super(context, textViewResourceId, objects);
		this._data = objects;
		this._context = context;
	}

	@SuppressLint("DefaultLocale")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) _context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(
				esgi.stationratp.R.layout.listview_item_row, parent, false);

		TextView textview = (TextView) rowView
				.findViewById(esgi.stationratp.R.id.StationNametextView);

		// TextView textview1 = (TextView)rowView.
		// findViewById(esgi.stationratp.R.id.StationSubTitletextView);

		ImageView imageview = (ImageView) rowView
				.findViewById(esgi.stationratp.R.id.StationTypeImageView);

		textview.setText(_data.get(position).getNom());
		// textview1.setText(_data.get(position).getVille());

		String stationReseau = _data.get(position).getReseau();

		if (stationReseau != null) {
			if (stationReseau.equals("metro")) {
				imageview.setImageResource(esgi.stationratp.R.drawable.metro);
			} else if (stationReseau.equals("rer")) {
				imageview.setImageResource(esgi.stationratp.R.drawable.rer);
			} else if (stationReseau.equals("tram")) {
				imageview.setImageResource(esgi.stationratp.R.drawable.tram);
			}
		}
		return rowView;
	}
}
